home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Cross Platform / QuickTime 4.1.2 Windows SDK / CIncludes / MixedMode.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-12  |  25.8 KB  |  688 lines  |  [TEXT/R*ch]

  1. /*
  2.      File:        MixedMode.h
  3.  
  4.      Contains:    Mixed Mode Manager Interfaces.
  5.  
  6.      Version:    Technology:    Mac OS 8
  7.                  Release:    QuickTime 4.1
  8.  
  9.      Copyright:    (c) 1992-1999 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __MIXEDMODE__
  18. #define __MIXEDMODE__
  19.  
  20. #ifndef __MACTYPES__
  21.     #include <MacTypes.h>
  22. #endif
  23.  
  24.  
  25.  
  26.  
  27. #if PRAGMA_ONCE
  28. #pragma once
  29. #endif
  30.  
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34.  
  35. #if PRAGMA_IMPORT
  36. #pragma import on
  37. #endif
  38.  
  39. #if PRAGMA_STRUCT_ALIGN
  40.     #pragma options align=mac68k
  41. #elif PRAGMA_STRUCT_PACKPUSH
  42.     #pragma pack(push, 2)
  43. #elif PRAGMA_STRUCT_PACK
  44.     #pragma pack(2)
  45. #endif
  46.  
  47. /* Mixed Mode constants */
  48. /* Current Routine Descriptor Version */
  49. enum {
  50.     kRoutineDescriptorVersion    = 7
  51. };
  52.  
  53. /* MixedModeMagic Magic Cookie/Trap number */
  54. enum {
  55.     _MixedModeMagic                = 0xAAFE
  56. };
  57.  
  58. /* MixedModeState Version for CFM68K Mixed Mode */
  59. enum {
  60.     kCurrentMixedModeStateRecord = 1
  61. };
  62.  
  63. /* Calling Conventions */
  64. typedef unsigned short                     CallingConventionType;
  65. enum {
  66.     kPascalStackBased            = 0,
  67.     kCStackBased                = 1,
  68.     kRegisterBased                = 2,
  69.     kD0DispatchedPascalStackBased = 8,
  70.     kD1DispatchedPascalStackBased = 12,
  71.     kD0DispatchedCStackBased    = 9,
  72.     kStackDispatchedPascalStackBased = 14,
  73.     kThinkCStackBased            = 5
  74. };
  75.  
  76. /* ISA Types */
  77. typedef SInt8                             ISAType;
  78. enum {
  79.     kM68kISA                    = 0,
  80.     kPowerPCISA                    = 1
  81. };
  82.  
  83. /* RTA Types */
  84. typedef SInt8                             RTAType;
  85. enum {
  86.     kOld68kRTA                    = 0 << 4,
  87.     kPowerPCRTA                    = 0 << 4,
  88.     kCFM68kRTA                    = 1 << 4
  89. };
  90.  
  91.  
  92. #if TARGET_CPU_PPC
  93.     #define        GetCurrentISA()        ((ISAType) kPowerPCISA)
  94.     #define        GetCurrentRTA()        ((RTAType) kPowerPCRTA)
  95. #elif TARGET_CPU_68K
  96.     #define        GetCurrentISA()        ((ISAType) kM68kISA)
  97.     #if TARGET_RT_MAC_CFM
  98.         #define    GetCurrentRTA()        ((RTAType) kCFM68kRTA)
  99.     #else
  100.         #define    GetCurrentRTA()        ((RTAType) kOld68kRTA)
  101.     #endif
  102. #endif
  103. #define        GetCurrentArchitecture()    (GetCurrentISA() | GetCurrentRTA())
  104.  
  105. /* Constants for specifing 68k registers */
  106. enum {
  107.     kRegisterD0                    = 0,
  108.     kRegisterD1                    = 1,
  109.     kRegisterD2                    = 2,
  110.     kRegisterD3                    = 3,
  111.     kRegisterD4                    = 8,
  112.     kRegisterD5                    = 9,
  113.     kRegisterD6                    = 10,
  114.     kRegisterD7                    = 11,
  115.     kRegisterA0                    = 4,
  116.     kRegisterA1                    = 5,
  117.     kRegisterA2                    = 6,
  118.     kRegisterA3                    = 7,
  119.     kRegisterA4                    = 12,
  120.     kRegisterA5                    = 13,
  121.     kRegisterA6                    = 14,                            /* A7 is the same as the PowerPC SP */
  122.     kCCRegisterCBit                = 16,
  123.     kCCRegisterVBit                = 17,
  124.     kCCRegisterZBit                = 18,
  125.     kCCRegisterNBit                = 19,
  126.     kCCRegisterXBit                = 20
  127. };
  128.  
  129. typedef unsigned short                     registerSelectorType;
  130. /* SizeCodes we use everywhere */
  131. enum {
  132.     kNoByteCode                    = 0,
  133.     kOneByteCode                = 1,
  134.     kTwoByteCode                = 2,
  135.     kFourByteCode                = 3
  136. };
  137.  
  138. /* Mixed Mode Routine Records */
  139. typedef unsigned long                     ProcInfoType;
  140. /* Routine Flag Bits */
  141. typedef unsigned short                     RoutineFlagsType;
  142. enum {
  143.     kProcDescriptorIsAbsolute    = 0x00,
  144.     kProcDescriptorIsRelative    = 0x01
  145. };
  146.  
  147. enum {
  148.     kFragmentIsPrepared            = 0x00,
  149.     kFragmentNeedsPreparing        = 0x02
  150. };
  151.  
  152. enum {
  153.     kUseCurrentISA                = 0x00,
  154.     kUseNativeISA                = 0x04
  155. };
  156.  
  157. enum {
  158.     kPassSelector                = 0x00,
  159.     kDontPassSelector            = 0x08
  160. };
  161.  
  162. enum {
  163.     kRoutineIsNotDispatchedDefaultRoutine = 0x00,
  164.     kRoutineIsDispatchedDefaultRoutine = 0x10
  165. };
  166.  
  167. enum {
  168.     kProcDescriptorIsProcPtr    = 0x00,
  169.     kProcDescriptorIsIndex        = 0x20
  170. };
  171.  
  172.  
  173. struct RoutineRecord {
  174.     ProcInfoType                     procInfo;                    /* calling conventions */
  175.     SInt8                             reserved1;                    /* Must be 0 */
  176.     ISAType                         ISA;                        /* Instruction Set Architecture */
  177.     RoutineFlagsType                 routineFlags;                /* Flags for each routine */
  178.     ProcPtr                         procDescriptor;                /* Where is the thing we're calling? */
  179.     UInt32                             reserved2;                    /* Must be 0 */
  180.     UInt32                             selector;                    /* For dispatched routines, the selector */
  181. };
  182. typedef struct RoutineRecord            RoutineRecord;
  183. typedef RoutineRecord *                    RoutineRecordPtr;
  184. typedef RoutineRecordPtr *                RoutineRecordHandle;
  185. /* Mixed Mode Routine Descriptors */
  186. /* Definitions of the Routine Descriptor Flag Bits */
  187.  
  188. typedef UInt8                             RDFlagsType;
  189. enum {
  190.     kSelectorsAreNotIndexable    = 0x00,
  191.     kSelectorsAreIndexable        = 0x01
  192. };
  193.  
  194. /* Routine Descriptor Structure */
  195.  
  196. struct RoutineDescriptor {
  197.     UInt16                             goMixedModeTrap;            /* Our A-Trap */
  198.     SInt8                             version;                    /* Current Routine Descriptor version */
  199.     RDFlagsType                     routineDescriptorFlags;        /* Routine Descriptor Flags */
  200.     UInt32                             reserved1;                    /* Unused, must be zero */
  201.     UInt8                             reserved2;                    /* Unused, must be zero */
  202.     UInt8                             selectorInfo;                /* If a dispatched routine, calling convention, else 0 */
  203.     UInt16                             routineCount;                /* Number of routines in this RD */
  204.     RoutineRecord                     routineRecords[1];            /* The individual routines */
  205. };
  206. typedef struct RoutineDescriptor        RoutineDescriptor;
  207. typedef RoutineDescriptor *                RoutineDescriptorPtr;
  208. typedef RoutineDescriptorPtr *            RoutineDescriptorHandle;
  209. /* 68K MixedModeStateRecord */
  210.  
  211. struct MixedModeStateRecord {
  212.     UInt32                             state1;
  213.     UInt32                             state2;
  214.     UInt32                             state3;
  215.     UInt32                             state4;
  216. };
  217. typedef struct MixedModeStateRecord        MixedModeStateRecord;
  218. #if CALL_NOT_IN_CARBON
  219. /* Macros for building static Routine Descriptors (not available in Carbon) */
  220.  
  221. /* A macro which creates a static instance of a non-dispatched routine descriptor */
  222. #define BUILD_ROUTINE_DESCRIPTOR(procInfo, procedure)                                 \
  223.     {                                                                                \
  224.         _MixedModeMagic,                            /* Mixed Mode A-Trap */         \
  225.         kRoutineDescriptorVersion,                    /* version */                    \
  226.         kSelectorsAreNotIndexable,                    /* RD Flags - not dispatched */    \
  227.         0,                                            /* reserved 1 */                \
  228.         0,                                            /* reserved 2 */                \
  229.         0,                                            /* selector info */                \
  230.         0,                                            /* number of routines */        \
  231.         {                                            /* It’s an array */                \
  232.             {                                        /* It’s a struct */                \
  233.                 (procInfo),                            /* the ProcInfo */                \
  234.                 0,                                    /* reserved */                    \
  235.                 GetCurrentArchitecture(),             /* ISA and RTA */                \
  236.                 kProcDescriptorIsAbsolute |            /* Flags - it’s absolute addr */\
  237.                 kFragmentIsPrepared |                /* It’s prepared */                \
  238.                 kUseNativeISA,                        /* Always use native ISA */        \
  239.                 (ProcPtr)(procedure),                /* the procedure */                \
  240.                 0,                                    /* reserved */                    \
  241.                 0                                    /* Not dispatched */            \
  242.             }                                                                        \
  243.         }                                                                            \
  244.     }
  245.  
  246. /* a macro which creates a static instance of a fat routine descriptor */
  247. #define BUILD_FAT_ROUTINE_DESCRIPTOR(m68kProcInfo, m68kProcPtr, powerPCProcInfo, powerPCProcPtr)  \
  248.     {                                                                                \
  249.         _MixedModeMagic,                            /* Mixed Mode A-Trap */         \
  250.         kRoutineDescriptorVersion,                    /* version */                    \
  251.         kSelectorsAreNotIndexable,                    /* RD Flags - not dispatched */    \
  252.         0,                                            /* reserved */                    \
  253.         0,                                            /* reserved */                    \
  254.         0,                                            /* reserved */                    \
  255.         1,                                            /* Array count */                \
  256.         {                                            /* It’s an array */                \
  257.             {                                        /* It’s a struct */                \
  258.                 (m68kProcInfo),                        /* the ProcInfo */                \
  259.                 0,                                    /* reserved */                    \
  260.                 kM68kISA |                            /* ISA */                        \
  261.                 kOld68kRTA,                            /* RTA */                        \
  262.                 kProcDescriptorIsAbsolute |            /* Flags - it’s absolute addr */\
  263.                 kUseCurrentISA,                        /* Use current ISA */            \
  264.                 (ProcPtr)(m68kProcPtr),                /* the procedure */                \
  265.                 0,                                    /* reserved */                    \
  266.                 0,                                    /* reserved */                    \
  267.             },                                                                        \
  268.             {                                        /* It’s a struct */                \
  269.                 (powerPCProcInfo),                    /* the ProcInfo */                \
  270.                 0,                                    /* reserved */                    \
  271.                 GetCurrentArchitecture(),             /* ISA and RTA */                \
  272.                 kProcDescriptorIsAbsolute |            /* Flags - it’s absolute addr */\
  273.                 kFragmentIsPrepared |                /* It’s prepared */                \
  274.                 kUseCurrentISA,                        /* Always use current ISA */    \
  275.                 (ProcPtr)(powerPCProcPtr),            /* the procedure */                \
  276.                 0,                                    /* reserved */                    \
  277.                 0                                    /* reserved */                    \
  278.             }                                                                        \
  279.         }                                                                            \
  280.     }
  281. #endif /* CALL_NOT_IN_CARBON */
  282.  
  283. /* Mixed Mode ProcInfos */
  284. enum {
  285.                                                                 /* Calling Convention Offsets */
  286.     kCallingConventionWidth        = 4,
  287.     kCallingConventionPhase        = 0,
  288.     kCallingConventionMask        = 0x0F,                            /* Result Offsets */
  289.     kResultSizeWidth            = 2,
  290.     kResultSizePhase            = kCallingConventionWidth,
  291.     kResultSizeMask                = 0x30,                            /* Parameter offsets & widths */
  292.     kStackParameterWidth        = 2,
  293.     kStackParameterPhase        = (kCallingConventionWidth + kResultSizeWidth),
  294.     kStackParameterMask            = (long)0xFFFFFFC0,                /* Register Result Location offsets & widths */
  295.     kRegisterResultLocationWidth = 5,
  296.     kRegisterResultLocationPhase = (kCallingConventionWidth + kResultSizeWidth), /* Register Parameter offsets & widths */
  297.     kRegisterParameterWidth        = 5,
  298.     kRegisterParameterPhase        = (kCallingConventionWidth + kResultSizeWidth + kRegisterResultLocationWidth),
  299.     kRegisterParameterMask        = 0x7FFFF800,
  300.     kRegisterParameterSizePhase    = 0,
  301.     kRegisterParameterSizeWidth    = 2,
  302.     kRegisterParameterWhichPhase = kRegisterParameterSizeWidth,
  303.     kRegisterParameterWhichWidth = 3,                            /* Dispatched Stack Routine Selector offsets & widths */
  304.     kDispatchedSelectorSizeWidth = 2,
  305.     kDispatchedSelectorSizePhase = (kCallingConventionWidth + kResultSizeWidth), /* Dispatched Stack Routine Parameter offsets */
  306.     kDispatchedParameterPhase    = (kCallingConventionWidth + kResultSizeWidth + kDispatchedSelectorSizeWidth), /* Special Case offsets & widths */
  307.     kSpecialCaseSelectorWidth    = 6,
  308.     kSpecialCaseSelectorPhase    = kCallingConventionWidth,
  309.     kSpecialCaseSelectorMask    = 0x03F0
  310. };
  311.  
  312. enum {
  313.     kSpecialCase                = 0x000F                        /* (CallingConventionType) */
  314. };
  315.  
  316. enum {
  317.                                                                 /* all of the special cases enumerated.  The selector field is 6 bits wide */
  318.     kSpecialCaseHighHook        = 0,
  319.     kSpecialCaseCaretHook        = 0,                            /* same as kSpecialCaseHighHook */
  320.     kSpecialCaseEOLHook            = 1,
  321.     kSpecialCaseWidthHook        = 2,
  322.     kSpecialCaseTextWidthHook    = 2,                            /* same as kSpecialCaseWidthHook */
  323.     kSpecialCaseNWidthHook        = 3,
  324.     kSpecialCaseDrawHook        = 4,
  325.     kSpecialCaseHitTestHook        = 5,
  326.     kSpecialCaseTEFindWord        = 6,
  327.     kSpecialCaseProtocolHandler    = 7,
  328.     kSpecialCaseSocketListener    = 8,
  329.     kSpecialCaseTERecalc        = 9,
  330.     kSpecialCaseTEDoText        = 10,
  331.     kSpecialCaseGNEFilterProc    = 11,
  332.     kSpecialCaseMBarHook        = 12
  333. };
  334.  
  335.  
  336. /*
  337.     NOTES ON USING ROUTINE DESCRIPTOR FUNCTIONS
  338.     
  339.     When calling these routine from classic 68k code there are two possible intentions.
  340.  
  341.     The first is source compatibility with code ported to CFM (either PowerPC or 68k CFM). When
  342.     the code is compiled for CFM the functions create routine descriptors that can be used by
  343.     the mixed mode manager operating on that machine. When the code is compiled for classic 68k
  344.     these functions do nothing so that the code will run on Macintoshes that do not have a
  345.     mixed mode manager. The dual nature of these functions is achieved by turning the CFM calls
  346.     into "no-op" macros for classic 68k: You can put "NewRoutineDescriptor" in your source,
  347.     compile it for any runtime or instruction set architecture, and it will run correctly on the
  348.     intended runtime/instruction platform. All without source changes and/or conditional source.
  349.     
  350.     The other intention is for code that "knows" that it is executing as classic 68k runtime
  351.     and is specifically trying to call code of another architecture using mixed mode. Since the
  352.     routines were designed with classic <-> CFM source compatibility in mind this second case
  353.     is treated special. For classic 68k code to create routines descriptors for use by mixed mode
  354.     it must call the "Trap" versions of the routines (NewRoutineDescriptorTrap). These versions
  355.     are only available to classic 68k callers: rigging the interfaces to allow calling them
  356.     from CFM code will result in runtime failure because no shared library implements or exports
  357.     the functions.
  358.     
  359.  
  360.     This almost appears seamless until you consider "fat" routine descriptors and the advent of
  361.     CFM-68K. What does "fat" mean? CFM-68K is not emulated on PowerPC and PowerPC is not emulated
  362.     on CFM-68K. It makes no sense to create a routine descriptor having both a CFM-68K routine
  363.     and a PowerPC native routine pointer. Therefore "fat" is defined to be a mix of classic and
  364.     CFM for the hardware's native instruction set: on PowerPC fat is classic and PowerPC native,
  365.     on a 68k machine with CFM-68K installed fat is classic and CFM-68K.
  366.     
  367.     By definition fat routine descriptors are only constructed by code that is aware of the 
  368.     architecture it is executing as and that another architecture exists. Source compatibility
  369.     between code intented as pure classic and pure CFM is not an issue and so NewFatRoutineDescriptor
  370.     is not available when building pure classic code.
  371.     
  372.     NewFatRoutineDescriptorTrap is available to classic code on both PowerPC and CFM-68K. The
  373.     classic code can use the code fragment manager routine "FindSymbol" to obtain the address of 
  374.     a routine in a shared library and then construct a routine descriptor with both the CFM routine 
  375.     and classic    routine.
  376. */
  377.  
  378. #if TARGET_OS_MAC && TARGET_RT_MAC_CFM
  379. EXTERN_API( UniversalProcPtr )
  380. NewRoutineDescriptor            (ProcPtr                 theProc,
  381.                                  ProcInfoType             theProcInfo,
  382.                                  ISAType                 theISA);
  383.  
  384. EXTERN_API( void )
  385. DisposeRoutineDescriptor        (UniversalProcPtr         theProcPtr);
  386.  
  387. EXTERN_API( UniversalProcPtr )
  388. NewFatRoutineDescriptor            (ProcPtr                 theM68kProc,
  389.                                  ProcPtr                 thePowerPCProc,
  390.                                  ProcInfoType             theProcInfo);
  391.  
  392. #else
  393. #define DisposeRoutineDescriptor(theProcPtr)
  394. #define NewRoutineDescriptor(theProc, theProcInfo, theISA) ((UniversalProcPtr)theProc)
  395. /* Note that the call to NewFatRoutineDescriptor is undefined. */
  396. #endif  /* TARGET_OS_MAC && TARGET_RT_MAC_CFM */
  397.  
  398.  
  399. #if TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  400. /*
  401.     The "Trap" versions of the MixedMode calls are only for classic 68K clients that 
  402.     want to load and use CFM based code.
  403. */
  404. EXTERN_API( UniversalProcPtr )
  405. NewRoutineDescriptorTrap        (ProcPtr                 theProc,
  406.                                  ProcInfoType             theProcInfo,
  407.                                  ISAType                 theISA)                                TWOWORDINLINE(0x7000, 0xAA59);
  408.  
  409. EXTERN_API( void )
  410. DisposeRoutineDescriptorTrap    (UniversalProcPtr         theProcPtr)                            TWOWORDINLINE(0x7001, 0xAA59);
  411.  
  412. EXTERN_API( UniversalProcPtr )
  413. NewFatRoutineDescriptorTrap        (ProcPtr                 theM68kProc,
  414.                                  ProcPtr                 thePowerPCProc,
  415.                                  ProcInfoType             theProcInfo)                        TWOWORDINLINE(0x7002, 0xAA59);
  416.  
  417. #endif  /* TARGET_CPU_68K && !TARGET_RT_MAC_CFM */
  418.  
  419. #if !TARGET_CPU_68K || TARGET_RT_MAC_CFM
  420. /*
  421.     CallUniversalProc is defined for all targets except classic 68k code.  This will 
  422.     catch accidental calls from classic 68K code that previously only showed up as 
  423.     linker errors.
  424. */
  425. EXTERN_API_C( long )
  426. CallUniversalProc                (UniversalProcPtr         theProcPtr,
  427.                                  ProcInfoType             procInfo,
  428.                                  ...);
  429.  
  430. EXTERN_API_C( long )
  431. CallOSTrapUniversalProc            (UniversalProcPtr         theProcPtr,
  432.                                  ProcInfoType             procInfo,
  433.                                  ...);
  434.  
  435. #endif  /* !TARGET_CPU_68K || TARGET_RT_MAC_CFM */
  436.  
  437. #if TARGET_CPU_68K
  438. EXTERN_API( OSErr )
  439. SaveMixedModeState                (MixedModeStateRecord *    stateStorage,
  440.                                  UInt32                 stateVersion)                        TWOWORDINLINE(0x7003, 0xAA59);
  441.  
  442. EXTERN_API( OSErr )
  443. RestoreMixedModeState            (MixedModeStateRecord *    stateStorage,
  444.                                  UInt32                 stateVersion)                        TWOWORDINLINE(0x7004, 0xAA59);
  445.  
  446. #endif  /* TARGET_CPU_68K */
  447.  
  448. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
  449.  *
  450.  *    Macros for building ProcInfos.  Examples:
  451.  *    
  452.  *    
  453.  *    uppModalFilterProcInfo = kPascalStackBased
  454.  *         | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
  455.  *         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DialogPtr)))
  456.  *         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(EventRecord*)))
  457.  *         | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short*))),
  458.  *
  459.  *    uppDeskHookProcInfo = kRegisterBased
  460.  *         | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(Boolean)))
  461.  *         | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(EventRecord*)))
  462.  *
  463.  *    uppGXSpoolResourceProcInfo = kCStackBased
  464.  *         | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  465.  *         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(gxSpoolFile)))
  466.  *         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
  467.  *         | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(ResType)))
  468.  *         | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
  469.  *
  470.  *    uppTEFindWordProcInfo = SPECIAL_CASE_PROCINFO( 6 ),
  471.  *
  472.  */
  473.  
  474.  
  475. /* * * * * * * * * * * * * * 
  476.  *    SIZE_CODE -     Return the size code for an object, given its size in bytes.
  477.  *        size - size of an object in bytes
  478.  */
  479. #define SIZE_CODE(size) \
  480.     (((size) == 4) ? kFourByteCode : (((size) == 2) ? kTwoByteCode : (((size) == 1) ? kOneByteCode : 0)))
  481.  
  482.  
  483. /* * * * * * * * * * * * * * 
  484.  *    RESULT_SIZE -     Return the result field of a ProcInfo, given the return object’s size.
  485.  *                     This is the same for all ProcInfos
  486.  *        sizeCode - size code
  487.  */
  488. #define RESULT_SIZE(sizeCode) \
  489.     ((ProcInfoType)(sizeCode) << kResultSizePhase)
  490.  
  491.  
  492. /* * * * * * * * * * * * * * 
  493.  *    STACK_ROUTINE_PARAMETER -    Return a parameter field of a ProcInfo, for a simple,
  494.  *                                non-dispatched, stack based routine.
  495.  *        whichParam - which parameter
  496.  *        sizeCode - size code
  497.  */
  498. #define STACK_ROUTINE_PARAMETER(whichParam, sizeCode) \
  499.     ((ProcInfoType)(sizeCode) << (kStackParameterPhase + (((whichParam) - 1) * kStackParameterWidth)))
  500.  
  501.  
  502. /* * * * * * * * * * * * * * 
  503.  *    DISPATCHED_STACK_ROUTINE_PARAMETER -    Return a parameter field of a ProcInfo, for 
  504.  *                                            a dispatched, stack based routine.  The same
  505.  *                                            macro is used regardless of the type of
  506.  *                                            dispatching.
  507.  *        whichParam - which parameter
  508.  *        sizeCode - size code
  509.  */
  510. #define DISPATCHED_STACK_ROUTINE_PARAMETER(whichParam, sizeCode) \
  511.     ((ProcInfoType)(sizeCode) << (kDispatchedParameterPhase + (((whichParam) - 1) * kStackParameterWidth)))
  512.  
  513.  
  514. /* * * * * * * * * * * * * * 
  515.  *    DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE -    Return a the selector size field of a ProcInfo
  516.  *                                                for a dispatched, stack based routine.  The
  517.  *                                                same macro is used regardless of the type of
  518.  *                                                dispatching.
  519.  *        sizeCode - size code 
  520.  */
  521. #define DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(sizeCode) \
  522.     ((ProcInfoType)(sizeCode) << kDispatchedSelectorSizePhase)
  523.  
  524.  
  525. /* * * * * * * * * * * * * * 
  526.  *    REGISTER_RESULT_LOCATION -        Return the Result Location field of a ProcInfo, 
  527.  *                                    given the location.
  528.  *        whichReg - which register
  529.  */
  530. #define REGISTER_RESULT_LOCATION(whichReg) \
  531.     ((ProcInfoType)(whichReg) << kRegisterResultLocationPhase)
  532.  
  533.  
  534. /* * * * * * * * * * * * * * 
  535.  *    REGISTER_ROUTINE_PARAMETER -    Return a parameter field of a ProcInfo for a 
  536.  *                                    register based routine.
  537.  */
  538. #define REGISTER_ROUTINE_PARAMETER(whichParam, whichReg, sizeCode) \
  539.     ((((ProcInfoType)(sizeCode) << kRegisterParameterSizePhase) | ((ProcInfoType)(whichReg) << kRegisterParameterWhichPhase)) << \
  540.             (kRegisterParameterPhase + (((whichParam) - 1) * kRegisterParameterWidth)))
  541.  
  542.  
  543. /* * * * * * * * * * * * * * 
  544.  *
  545.  *    SPECIAL_CASE_PROCINFO -     Returns the procInfo constant for the following special cases:
  546.  *    
  547.  *        High Hook & Caret Hook -  (see I-379)
  548.  *            C calling conventions, Rect on stack, pointer in A3, no return value
  549.  *        EOL Hook - (see VI-15-26)
  550.  *            Register-based; inputs in D0, A3, A4; 
  551.  *            output is Z flag of status register
  552.  *        Width Hook - (see VI-15-27)
  553.  *            Register-based; inputs in D0, D1, A0, A3, A4; output in D1 
  554.  *        NWidth Hook - (see VI-15-27)
  555.  *            Register-based; inputs in D0, D1, D2, A0, A2, A3, A4; output in D1 
  556.  *        TextWidthHook - (see VI-15-28)
  557.  *            Register-based; inputs in D0, D1, A0, A3, A4; output in D1 
  558.  *        DrawHook - (see VI-15-28)
  559.  *            Register-based; inputs in D0, D1, A0, A3, A4; no output
  560.  *        HitTestHook - (See VI-15-29)
  561.  *            Register-based; inputs in D0, D1, D2, A0, A3, A4; outputs in D0, D1, D2
  562.  *        FindWord -  (see VI-15-30)
  563.  *            Register-based; inputs in D0, D2, A3, A4; outputs in D0, D1
  564.  *        ADBRoutines - (see V-371)
  565.  *            Register-based; inputs in A0, A1, A2, D0; no outputs
  566.  *        ProtocolHandler - (see II-326)
  567.  *            Register-based; inputs in A0, A1, A2, A3, A4, D1.w; output in Z 
  568.  *        SocketListener - (see II-329)
  569.  *            Register-based; inputs in A0, A1, A2, A3, A4, D0.b, D1.w; output in Z 
  570.  *        Reclac - (see I-391)
  571.  *            Register-based; inputs in A3, D7; outputs in D2, D3, D4
  572.  *        DoText - (see I-391)
  573.  *            Register-based; inputs in A3, D3, D4, D7; outputs in A0, D0
  574.  *        GNEFilterProc - (see tech note 85)
  575.  *            Register & Stack Based; inputs in A1, D0 & on the stack; outputs on the stack
  576.  *        MenuBarHook - (see I-356)
  577.  *            Register & Stack Based; input on the stack; output in D0
  578. */
  579. #define SPECIAL_CASE_PROCINFO(specialCaseCode)            \
  580.         (kSpecialCase | ((ProcInfoType)(specialCaseCode) << 4))
  581.  
  582.  
  583. /* * * * * * * * * * * * * * * 
  584.  *    STACK_UPP_TYPE    - used in typedefs to create ≈UPP type
  585.  *    REGISTER_UPP_TYPE - used in typedefs to create ≈UPP type
  586.  *    TVECTOR_UPP_TYPE  - used in typedefs to create ≈UPP type
  587.  *
  588.  *    Example:
  589.  *
  590.  *        typedef STACK_UPP_TYPE(ModalFilterProcPtr)         ModalFilterUPP;
  591.  *        typedef REGISTER_UPP_TYPE(IOCompletionProcPtr)     IOCompletionUPP;
  592.  *
  593.  */
  594. #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  595.     /* classic 68k runtime */
  596.     #define STACK_UPP_TYPE(name)     name
  597.     #define REGISTER_UPP_TYPE(name) Register68kProcPtr
  598.     #define TVECTOR_UPP_TYPE(name)  name
  599. #elif TARGET_OS_MAC && TARGET_RT_MAC_CFM
  600.     /* PowerPC and CFM68K runtime */
  601.     #if OPAQUE_UPP_TYPES
  602.         #define STACK_UPP_TYPE(name)     struct Opaque##name##*
  603.         #define REGISTER_UPP_TYPE(name) struct Opaque##name##*
  604.         #define TVECTOR_UPP_TYPE(name)  struct Opaque##name##*
  605.     #else
  606.         #define STACK_UPP_TYPE(name)     UniversalProcPtr
  607.         #define REGISTER_UPP_TYPE(name) UniversalProcPtr
  608.         #define TVECTOR_UPP_TYPE(name)  name
  609.     #endif
  610. #elif TARGET_OS_MAC && TARGET_RT_MAC_MACHO
  611.     /* Mac OS X runtime */
  612.     #define STACK_UPP_TYPE(name)     name
  613.     #define REGISTER_UPP_TYPE(name) name
  614.     #define TVECTOR_UPP_TYPE(name)  name
  615. #else
  616.     /* other runtimes */
  617.     #define STACK_UPP_TYPE(name)     name
  618.     #define REGISTER_UPP_TYPE(name) name
  619.     #define TVECTOR_UPP_TYPE(name)  name
  620. #endif
  621.  
  622.  
  623. /* * * * * * * * * * * * * * * 
  624.  *    CALL_≈_PARAMETER_UPP  - used in Call≈Proc macros
  625.  *
  626.  *    Example:
  627.  *
  628.  *        #define CallIOCompletionProc(userRoutine, paramBlock)     \
  629.  *                CALL_TWO_PARAMETER_UPP((userRoutine), uppIOCompletionProcInfo, (paramBlock))
  630.  *
  631.  */
  632. #if TARGET_OS_MAC && TARGET_RT_MAC_CFM
  633.     #define CALL_ZERO_PARAMETER_UPP(    upp, procInfo)         CallUniversalProc(upp, procInfo)
  634.     #define CALL_ONE_PARAMETER_UPP(     upp, procInfo, p1)         CallUniversalProc(upp, procInfo, (p1))
  635.     #define CALL_TWO_PARAMETER_UPP(     upp, procInfo, p1, p2)         CallUniversalProc(upp, procInfo, (p1), (p2))
  636.     #define CALL_THREE_PARAMETER_UPP(   upp, procInfo, p1, p2, p3)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3))
  637.     #define CALL_FOUR_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4))
  638.     #define CALL_FIVE_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4, p5)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5))
  639.     #define CALL_SIX_PARAMETER_UPP(     upp, procInfo, p1, p2, p3, p4, p5, p6)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6))
  640.     #define CALL_SEVEN_PARAMETER_UPP(   upp, procInfo, p1, p2, p3, p4, p5, p6, p7)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7))
  641.     #define CALL_EIGHT_PARAMETER_UPP(   upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8))
  642.     #define CALL_NINE_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9))
  643.     #define CALL_TEN_PARAMETER_UPP(     upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)     CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10))
  644.     #define CALL_ELEVEN_PARAMETER_UPP(  upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11)     CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11))
  645.     #define CALL_TWELVE_PARAMETER_UPP(  upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12)    CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12))
  646.     #define CALL_THIRTEEN_PARAMETER_UPP(upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13)    CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12), (p13))
  647. #else
  648.     #define CALL_ZERO_PARAMETER_UPP(    upp, procInfo)         (*(upp))()
  649.     #define CALL_ONE_PARAMETER_UPP(     upp, procInfo, p1)         (*(upp))((p1))
  650.     #define CALL_TWO_PARAMETER_UPP(     upp, procInfo, p1, p2)         (*(upp))((p1), (p2))
  651.     #define CALL_THREE_PARAMETER_UPP(   upp, procInfo, p1, p2, p3)         (*(upp))((p1), (p2), (p3))
  652.     #define CALL_FOUR_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4)         (*(upp))((p1), (p2), (p3), (p4))
  653.     #define CALL_FIVE_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4, p5)         (*(upp))((p1), (p2), (p3), (p4), (p5))
  654.     #define CALL_SIX_PARAMETER_UPP(     upp, procInfo, p1, p2, p3, p4, p5, p6)         (*(upp))((p1), (p2), (p3), (p4), (p5), (p6))
  655.     #define CALL_SEVEN_PARAMETER_UPP(   upp, procInfo, p1, p2, p3, p4, p5, p6, p7)         (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7))
  656.     #define CALL_EIGHT_PARAMETER_UPP(   upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8)         (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8))
  657.     #define CALL_NINE_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9)         (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9))
  658.     #define CALL_TEN_PARAMETER_UPP(     upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)     (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10))
  659.     #define CALL_ELEVEN_PARAMETER_UPP(  upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11)     (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11))
  660.     #define CALL_TWELVE_PARAMETER_UPP(  upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12)     (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12))
  661.     #define CALL_THIRTEEN_PARAMETER_UPP(upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13)     (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12), (p13))
  662. #endif
  663.  
  664.  
  665.  
  666.  
  667.  
  668. #if PRAGMA_STRUCT_ALIGN
  669.     #pragma options align=reset
  670. #elif PRAGMA_STRUCT_PACKPUSH
  671.     #pragma pack(pop)
  672. #elif PRAGMA_STRUCT_PACK
  673.     #pragma pack()
  674. #endif
  675.  
  676. #ifdef PRAGMA_IMPORT_OFF
  677. #pragma import off
  678. #elif PRAGMA_IMPORT
  679. #pragma import reset
  680. #endif
  681.  
  682. #ifdef __cplusplus
  683. }
  684. #endif
  685.  
  686. #endif /* __MIXEDMODE__ */
  687.  
  688.